<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\index\controller;

use app\admin\model\CepingCategoryModel;
use app\admin\model\CepingModel;
use cmf\controller\HomeBaseController;
use think\Db;

class IndexController extends HomeBaseController
{
    //PC站
    public function index()
    {
        $CepingModel = new CepingModel();
        $Category    = new CepingCategoryModel();
        if ($this->request->isPost() &&$this->request->param('category_id')){
            $category_id = $this->request->param('category_id');
            $cepings = $CepingModel->where('category_id',$category_id)->select();

        }else{
            $category_id = 0;
            $cepings = $CepingModel->select();
        }

        $categories = $Category->select();
        $list = array();
        foreach ($cepings as $v){
            foreach ($categories as $val){
                if ($v['category_id'] == $val['id']){
                    $v['category'] = $val['name'];
                }
            }
            $list[] = $v;
        }
        $this->assign('categories', $categories);
        $this->assign('category_id', $category_id);
        $this->assign('cepings', $list);
        return $this->fetch(':index');
    }

    //手机站
    public function mobile(){

        $CepingModel = new CepingModel();
        $Category    = new CepingCategoryModel();
        if ($this->request->isPost() &&$this->request->param('category_id')){
            $category_id = $this->request->param('category_id');
            $cepings = $CepingModel->where('category_id',$category_id)->select();

        }else{
            $category_id = 0;
            $cepings = $CepingModel->select();
        }

        $categories = $Category->select();
        $list = array();
        foreach ($cepings as $v){
            foreach ($categories as $val){
                if ($v['category_id'] == $val['id']){
                    $v['category'] = $val['name'];
                }
            }
            $list[] = $v;
        }
        $this->assign('categories', $categories);
        $this->assign('category_id', $category_id);
        $this->assign('cepings', $list);

        return $this->fetch(':mobile');
    }

    public function ws()
    {
        return $this->fetch(':ws');
    }
}
